let mysql = require("mysql");

let connection = mysql.createConnection({ host: 'localhost', port: '3306', user: 'root', password: '123456', database: 'School' });
connection.conect();

// 增加
let sqlInsert = `INSERT into Student(name,sex) VALUES ('张三', '1'),('李四', '1'),('王五', '2'),('赵六', '1'),('孙七','2')`;
connection.query(sqlInsert, function (err, rows) {
    if (err) {
        console.log('插入失败' + err.message)
    } else {
        console.log('插入成功');
    }
})

//删除
// let sqlDelete = `DELETE FROM Student WHERE sex=2`;
// connection.query(sqlDelete, function (err, data) {
//     if(err){
//         console.log('删除失败'+err.message)
//     }
//     console.log('删除成功');
// })

//修改
// let sqlUpdate = `UPDATE Student SET sex=2 WHERE name='张三'`;
// connection.query(sqlUpdate, function (err, data) {
//     if(err){
//         console.log('修改失败'+err.message)
//     }
//     console.log('修改成功');
// })

//查询
// let sqlSelect = `select * from Student`;
// connection.query(sqlSelect, function (err, rows) {
//     if (err) {
//         console.log(err.message);
//         return;
//     } for (let i in rows) {
//         console.log(rows[i].name, rows[i].sex);
//     }
// })
// connection.end();

